Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for 5.2 AST bump #276

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

patricoferris
Copy link

Note, I couldn't quite work out the right change to make to the trace_ppx -- I think it is something close to this change but it is not quite right. Hopefully you will have more luck, do you use the overlay for testing your changes if you have time.

PR details

This PR is a patch for an upcoming release of ppxlib where the internal AST is bumped from 4.14 to 5.2. Until that is merged and released, there is no reason to merge this PR.

To test these changes, you can use the following opam-based workflow. I've made releases of most of these patches to an opam-repository overlay.

opam switch create ppxlib-bump --repos=ppxlib=git+https://github.com/patricoferris/opam-repository#5.2-ast-bump
opam install <your-package>

The following describes the most notable changes to the AST.

Note: no update has been made of the opam file, but ppxlib will likely need a lower-bound before merging/releasing.

Functions


Currently

In the parsetree currently, functions like:

fun x y z -> ...

Are represented roughly as

Pexp_fun(x, Pexp_fun (y, Pexp_fun(z, ...)))

Functions like:

function A -> ... | B -> ...

Are represented roughly as

Pexp_function ([ case A; case B ])

Since 5.2

All of these functions now map to a single AST node Pexp_function (note, this is the same name as the old cases function). The first argument is a list of parameters meaning:

fun x y z -> ...

Now looks like:

Pexp_function([x; y; z], _constraint, body)

And the body is where we can either have more expressions (Pfunction_body _) or cases (Pfunction_cases _). That means:

function A -> ... | B -> ...

Has an empty list of parameters:

Pexp_function([], _, Pfunction_cases ([case A; case B]))

Local Module Opens for Types

Another feature added in 5.2 was the ability to locally open modules in type definitions.

module M = struct
  type t = A | B | C
end

type t = Local_open_coming of M.(t)

This has a Ptyp_open (module_identifier, core_type) AST node. Just like normal module opens this does create some syntactic ambiguity about where things come from inside the parentheses.

@gares
Copy link
Contributor

gares commented Oct 26, 2024

Looking at the code it looks OK, but you have reasons to suspect otherwise. What looks wrong to you?

That part of the ppx should elide function arguments carrying the trace attribute, as in fun x (y[@trace]) z -> to fun x z ->.
It seems you pay special care when the elided argument is the last one.

Anyway, maybe a simpler patch is to just filter the list of arguments the new AST features before doing a rec call? You kind of coalesce List.filter here, IMO.

Thanks for the patch.

@patricoferris
Copy link
Author

That part of the ppx should elide function arguments carrying the trace attribute, as in fun x (y[@trace]) z -> to fun x z ->.
It seems you pay special care when the elided argument is the last one.

Ah okay! I've repushed filtering out the params that have the trace attribute. These seems to build ok (previously it didn't). Not quite sure when you would recurse into the body of the function though.

| _ -> true
in
let params = List.filter does_not_have_iftrace_param params in
{ e with pexp_desc = Pexp_function (params, constraint_, rest) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need to recurse on rest, params and constraint here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants